/*
 * QE3e Qt Quick 3D Engine.
 * Copyright (C) 2010 Joris Vaillant and Mathieu Pujol 
 * <joris.vaillant@gmail.com>  <mathieu.pujol87@gmail.com>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

// Associated header
#include "GroupItem.h"

namespace qe3e
{

  GroupItem::GroupItem(Item* parent)
    : Item(parent)
    , m_child()
    , m_bound()
  {
  }

  const QVector<Item*>& GroupItem::childItems() const
  {
    return m_child;
  }

  const QVector<Item*>& GroupItem::drawItems(const Camera& /* camera */) const
  {
    return m_child;
  }

  void GroupItem::drawGeometry() const
  {
  }

  const BoundingSphere& GroupItem::boundingSphere() const
  {
    return m_bound;
  }

  void GroupItem::addChild(Item* child)
  {
    m_child.append(child);
    m_bound.expand(child->boundingSphere());
    child->setParent(this);
  }

  void GroupItem::removeChild(Item* child)
  {
    m_child.remove(m_child.indexOf(child));
    child->setParent(0);
  }

  void GroupItem::removeChild(int pos)
  {
    removeChild(m_child[pos]);
  }

  bool GroupItem::childExist(Item* child) const
  {
    return m_child.contains(child);
  }

  int GroupItem::childCount() const
  {
    return m_child.size();
  }

  void GroupItem::calcBoundingSphere_()
  {
    m_bound.reset();
    for(QVector<Item*>::const_iterator it = m_child.constBegin();
        it != m_child.constEnd(); ++it)
    {
      m_bound.expand((*it)->boundingSphere());
    }
  }

}
